package com.yuandian.middle.platform.contoller;

import com.yuandian.api.middle_platform.po.OrgAbilityParam;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.middle.platform.service.IServerDetailService;
import com.yuandian.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 说明：服务调用详情controller
 * @Author tianlr
 * @Date 2023/5/23 13:58
 */
@Api(value = "serverDetail", tags = "服务调用详情接口")
@RestController
@RequestMapping("/modules/serverDetail")
public class ServerDetailController {

    @Autowired
    private IServerDetailService serverDetailService;

    /**
     * 查询中断时长（次数）变化趋势
     * @return
     */
    @PostMapping("/queryDataInterruptTimeTrend")
    @ApiOperation(value = "查询中断时长（次数）变化趋势", notes = "查询中断时长（次数）变化趋势，必填参数：startTime、endTime、abilityCode、serviceCode")
    public R queryDataInterruptTimeTrend(@RequestBody OrgAbilityParam param) {
        if (param == null || StringUtils.isEmpty(param.getAbilityCode()) || StringUtils.isEmpty(param.getServiceCode())
                || StringUtils.isEmpty(param.getStartTime()) || StringUtils.isEmpty(param.getEndTime())) {
            return R.failed("传入参数不正确！abilityCode和startTime、endTime、serviceCode不能为空");
        }
        return serverDetailService.selectDataInterruptTimeTrend(param);
    }

    /**
     * 查询访问量最大的服务器TopN
     * @return
     */
    @PostMapping("/queryDataRequestCountTopN")
    @ApiOperation(value = "查询访问量最大的服务器TopN", notes = "查询访问量最大的服务器TopN，必填参数：startTime、endTime、abilityCode、serviceCode")
    public R queryDataRequestCountTopN(@RequestBody OrgAbilityParam param) {
        if (param == null || StringUtils.isEmpty(param.getAbilityCode()) || StringUtils.isEmpty(param.getServiceCode())
                || StringUtils.isEmpty(param.getStartTime()) || StringUtils.isEmpty(param.getEndTime())) {
            return R.failed("传入参数不正确！abilityCode和startTime、endTime、serviceCode不能为空");
        }
        return serverDetailService.selectDataRequestCountTopN(param);
    }

    /**
     * 查询新建会话量最大的服务器TopN
     * @return
     */
    @PostMapping("/queryDataNewSessionCountTopN")
    @ApiOperation(value = "查询新建会话量最大的服务器TopN", notes = "查询新建会话量最大的服务器TopN，必填参数：startTime、endTime、abilityCode、serviceCode")
    public R queryDataNewSessionCountTopN(@RequestBody OrgAbilityParam param) {
        if (param == null || StringUtils.isEmpty(param.getAbilityCode()) || StringUtils.isEmpty(param.getServiceCode())
                || StringUtils.isEmpty(param.getStartTime()) || StringUtils.isEmpty(param.getEndTime())) {
            return R.failed("传入参数不正确！abilityCode和startTime、endTime、serviceCode不能为空");
        }
        return serverDetailService.selectDataNewSessionCountTopN(param);
    }

    /**
     * 查询系统返回码统计
     * @return
     */
    @PostMapping("/queryDataServerResCodeStatistics")
    @ApiOperation(value = "查询系统返回码统计", notes = "查询系统返回码统计，必填参数：startTime、endTime、abilityCode、serviceCode")
    public R queryDataServerResCodeStatistics(@RequestBody OrgAbilityParam param) {
        if (param == null || StringUtils.isEmpty(param.getAbilityCode()) || StringUtils.isEmpty(param.getServiceCode())
                || StringUtils.isEmpty(param.getStartTime()) || StringUtils.isEmpty(param.getEndTime())) {
            return R.failed("传入参数不正确！abilityCode和startTime、endTime、serviceCode不能为空");
        }
        return serverDetailService.selectDataServerResCodeStatistics(param);
    }

    /**
     * 查询业务返回码统计
     * @return
     */
    @PostMapping("/queryDataBusinessResCodeStatistics")
    @ApiOperation(value = "查询业务返回码统计", notes = "查询业务返回码统计，必填参数：startTime、endTime、abilityCode、serviceCode")
    public R queryDataBusinessResCodeStatistics(@RequestBody OrgAbilityParam param) {
        if (param == null || StringUtils.isEmpty(param.getAbilityCode()) || StringUtils.isEmpty(param.getServiceCode())
                || StringUtils.isEmpty(param.getStartTime()) || StringUtils.isEmpty(param.getEndTime())) {
            return R.failed("传入参数不正确！abilityCode和startTime、endTime、serviceCode不能为空");
        }
        return serverDetailService.selectDataBusinessResCodeStatistics(param);
    }

    /**
     * 查询TCP分析数据
     * @return
     */
    @PostMapping("/queryDataTcp")
    @ApiOperation(value = "查询TCP分析数据", notes = "查询TCP分析数据，必填参数：startTime、endTime、abilityCode、serviceCode")
    public R queryDataTcp(@RequestBody OrgAbilityParam param) {
        if (param == null || StringUtils.isEmpty(param.getAbilityCode()) || StringUtils.isEmpty(param.getServiceCode())
                || StringUtils.isEmpty(param.getStartTime()) || StringUtils.isEmpty(param.getEndTime())) {
            return R.failed("传入参数不正确！abilityCode和startTime、endTime、serviceCode不能为空");
        }
        return serverDetailService.selectDataTcp(param);
    }

    /**
     * 查询服务调用详情
     * @return
     */
    @PostMapping("/queryDataDeatil")
    @ApiOperation(value = "查询服务调用详情", notes = "查询服务调用详情，必填参数：startTime、endTime、abilityCode、serviceCode")
    public R queryDataDeatil(@RequestBody OrgAbilityParam param) {
        if (param == null || StringUtils.isEmpty(param.getAbilityCode()) || StringUtils.isEmpty(param.getServiceCode())
                || StringUtils.isEmpty(param.getStartTime()) || StringUtils.isEmpty(param.getEndTime())) {
            return R.failed("传入参数不正确！abilityCode和startTime、endTime、serviceCode不能为空");
        }
        return serverDetailService.selectDataDetail(param);
    }
}

